<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router_3.0.2.js"></script>
</head>
<body>
<div id="div1">
    <!--
    /users/1    动态传输参数  1
     -->
    <router-link to="/users/1" >用户模块1</router-link>
    <router-link to="/users/2" >用户模块2</router-link>
    <router-link to="/users/3" >用户模块3</router-link>
    <router-link to="/users/4" >用户模块4</router-link>
    <router-link to="/products" >商品模块</router-link>
    <!-- 占位符: 显示点击的组件对应的模板内容 -->
    <router-view></router-view>
</div>
<script>
    const users = {
        props: ['id', 'username', 'gender'],
        template: '<h1>用户模块 当前的id= {{id}}  姓名：{{username}} 性别：{{gender}}</h1>'
    }

    const products = {
        template: '<h1>商品模块</h1>'
    }

    // 创建路由对象
    const router = new VueRouter({
        /*
           动态接受参数
            解决id传递的问题

             {username: '东方不败', gender: '女'}
         */
        routes: [
            {path: '/', redirect: '/users/1'},
            {path: '/users/:id', component: users, props:route => ({username: '东方不败', gender: '女',id:route.params.id})},
            {path: '/products', component: products},
        ]
    });

    const vm = new Vue({
        el: '#div1',
        data: {},
        // 挂载路由对象
        // router:router 写法一
        router

    })
</script>
</body>
</html>